package com.qy.service.impl;

import com.qy.dao.EnshrineMapper;
import com.qy.model.Enshrine;
import com.qy.service.EnshrineService;
import com.qy.base.core.AbstractService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * Created by zaq on 2018/07/10.
 */
@Service
@Transactional
public class EnshrineServiceImpl extends AbstractService<Enshrine> implements EnshrineService {
    @Resource
    private EnshrineMapper qyEnshrineMapper;

    @Resource
    private EnshrineService enshrineService;

    @Override
    public Integer selectEnshrineState(Integer user_id, Integer goods_id, Integer goods_type) {
        Condition condition = new Condition(Enshrine.class);
        Example.Criteria criteria = condition.createCriteria();
        criteria.andCondition("user_id =" + user_id);
        if (goods_type == 1) {
            criteria.andCondition("policy_id =" + goods_id);
        } else if (goods_type == 2) {
            criteria.andCondition("unit_id =" + goods_id);
        } else if (goods_type == 3) {
            criteria.andCondition("charge_id =" + goods_id);
        }
        List<Enshrine> enshrineList = enshrineService.findByCondition(condition);
        Integer enshrineState;
        if (enshrineList.size() == 0) {
            enshrineState = 1;//未收藏
        } else {
            enshrineState = 2;//已收藏
        }
        return enshrineState;
    }

    @Override
    public List<Map> selectPolicyEnshrine(Enshrine enshrine) {
        return qyEnshrineMapper.selectPolicyEnshrine(enshrine);
    }

    @Override
    public List<Map> selectUnitEnshrine(Enshrine enshrine) {
        return qyEnshrineMapper.selectUnitEnshrine(enshrine);
    }

    @Override
    public List<Map> selectChargeEnshrine(Enshrine enshrine) {
        return qyEnshrineMapper.selectChargeEnshrine(enshrine);
    }
}
